package com.gjm.demo.Message;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;

@RequestMapping("/message")
@RestController
public class messageController {

    List<MessageInfo> messageList = new ArrayList<>();

    @PostMapping(value = "/publish", produces = "application/json")
    public String publish(@RequestBody MessageInfo messageInfo) {
        if (!StringUtils.hasLength(messageInfo.getSender()) ||
            !StringUtils.hasLength(messageInfo.getReceiver()) ||
            !StringUtils.hasLength(messageInfo.getMessage())) {
            return "{\"ok\" : 0}";
        }
        messageList.add(messageInfo);
        return "{\"ok\" : 1}";
    }

    @GetMapping("/getList")
    public List<MessageInfo> getList() {
        return messageList;
    }
}
